<template>
	<view>
		<uni-nav-bar :title="title" :statusBar="true" :border="false" left-icon="back" :fixed="true"
			@clickLeft="$tab.back()">
		</uni-nav-bar>

		<view class="px-20 py-24 bg-FFF mt-16">
			<u-search placeholder="手机号/昵称" v-model="keyword" @custom="refresh"></u-search>
		</view>

		<view class="px-20 py-28 bg-FFF mt-16">
			<s-pull-scroll ref="pullScroll" :pullDown="pullDown" :pullUp="loadData" :fixed="false">
				<view class="grid grid-cols-5 gap-4">
					<view class="flex flex-col items-center" v-for="(item,index) in userList" :key="item.id"
						@click="hendClick(item)">
						<image :src="item.userInfo.avatar" class="image-80 round" mode=""></image>
						<view class="text-9E9E9E mt-12 text-20 u-line-1">
							{{item.userInfo.nickName}}
						</view>
					</view>
				</view>
			</s-pull-scroll>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userList: null,
				id: null,
				title: "",
				keyword: "",
			};
		},
		onLoad(e) {
			this.id = e.id
			this.title = e.title
			this.refresh()
		},
		methods: {
			async hendClick(item) {
				const res = await this.$Api.chat.usersIsFriend({
					userId1: item.userInfo.userId
				})
				if (res.data) {
					this.$tab.nav(`/pages/chat2/userDetail?userId=${item.userInfo.userId}`)
				} else {
					this.$tab.nav(`/pages/chat2/addFriend?userName=${item.userInfo.userId}`)
				}
			},
			async getDetail() {
				const res = await this.$Api.chat.groupUserList({
					groupId: this.id,
					keyword: this.keyword
				})
				this.userList = res.rows
			},
			refresh() {
				this.$nextTick(() => {
					this.$refs.pullScroll.refresh();
				});
			},
			pullDown(pullScroll) {
				setTimeout(() => {
					this.loadData(pullScroll);
				}, 200);
			},
			loadData(pullScroll) {
				setTimeout(async () => {
					if (pullScroll.page == 1) {
						this.userList = [];
					}
					const res = await this.$Api.chat.groupUserList({
						groupId: this.id,
						keyword: this.keyword,
						pageNum: pullScroll.page,
						pageSize: 100
					})

					this.userList = this.userList.concat(res.rows);
					if (this.userList.length >= res.total) {
						pullScroll.finish();
					} else {
						pullScroll.success();
					}
				}, 500);
			}
		}
	}
</script>

<style lang="scss">

</style>